package com.zbf.connConfig;

import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class ConnConfig {

    @Bean
    public OkHttpClient getOkHttpClient(){
        //1构建OKHttpClient客户端
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                //发请求给对方传递数据的超时时间
                .writeTimeout(100, TimeUnit.SECONDS)
                //接收请求返回的数据的超时时间(适合于对方服务器处理业务时间比较长的场景)
                .readTimeout(50, TimeUnit.SECONDS)
                //链接的超时时间
                .connectTimeout(100, TimeUnit.SECONDS)
                //等待创建请求的超时时间
                .callTimeout(100, TimeUnit.SECONDS)
                .connectionPool(new ConnectionPool(100,100,TimeUnit.SECONDS))
                .build();
        return okHttpClient;
    }

}
